//
//  SYUploadView.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/4/15.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#import "SYUploadView.h"

@interface SYUploadView ()

@property (strong, nonatomic) UIView *bgView;
@property (strong, nonatomic) UIImageView *bgImageView;
@property (strong, nonatomic) SYUploadView *uploadView;
@property (strong, nonatomic) UIButton *paiZhaoBtn;//拍照
@property (strong, nonatomic) UIButton *zhaoPianBtn;//照片
@property (strong, nonatomic) UIButton *liulanBtn;//浏览


@end


@implementation SYUploadView

- (instancetype)init {
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self addSubview:self.bgView];
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.bottom.equalTo(self);
        }];
    }
    return self;
}



- (void)showUploadView:(UIButton *)btn uploadView:(SYUploadView *)uploadView {
    _uploadView = uploadView;
    UIWindow *window = [UIApplication sharedApplication].windows.firstObject;
    uploadView.frame = CGRectMake(0, 0, APP_WIDTH, APP_HEIGHT);
    [window addSubview:uploadView];
    
    
    
    [uploadView addSubview:self.bgImageView];

    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(btn.mas_centerX).offset(50);
        make.top.equalTo(btn.mas_bottom);
        make.width.mas_equalTo(147);
        make.height.mas_equalTo(130);
    }];
    

    
    [self.bgImageView addSubview:self.paiZhaoBtn];
    [self.paiZhaoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgImageView.mas_top).offset(10);
        make.left.right.equalTo(self.bgImageView);
        make.height.mas_equalTo(120/3);
    }];
    
    [self.bgImageView addSubview:self.zhaoPianBtn];
    [self.zhaoPianBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.paiZhaoBtn.mas_bottom).offset(0);
        make.left.right.equalTo(self.bgImageView);
        make.height.mas_equalTo(120/3);
    }];
    
    [self.bgImageView addSubview:self.liulanBtn];
    [self.liulanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.zhaoPianBtn.mas_bottom).offset(0);
        make.left.right.equalTo(self.bgImageView);
        make.height.mas_equalTo(120/3);
    }];
    
}

- (void)btnClick:(UIButton *)send {
    NSInteger type = send.tag;
    SYUploadViewType staun = 0 ;
    switch (type) {
        case 1101://拍照
            staun = SYUploadViewTypePaiZhao;
            break;
        case 1102://照片
            staun = SYUploadViewTypeZhaoPian;
            break;
        case 1103://浏览
            staun = SYUploadViewTypeLiuLan;
            break;
        default:
            break;
    }
}

#pragma mark -
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = [UIColor blackColor];
        _bgView.alpha = 0.3;
    }
    return _bgView;
}

- (UIImageView *)bgImageView {
    if (!_bgImageView) {
        _bgImageView = [[UIImageView alloc] init];
//        _bgImageView.backgroundColor = [UIColor yellowColor];
        _bgImageView.image = [UIImage imageNamed:@"zy_add_tianjia"];
    }
    return _bgImageView;
}

- (UIButton *)paiZhaoBtn {
    if (!_paiZhaoBtn) {
        _paiZhaoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_paiZhaoBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
//        _paiZhaoBtn.backgroundColor = [UIColor redColor];
        _paiZhaoBtn.tag = 1101;
    }
    return _paiZhaoBtn;
}

- (UIButton *)zhaoPianBtn {
    if (!_zhaoPianBtn) {
        _zhaoPianBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_zhaoPianBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _zhaoPianBtn.tag = 1102;
//        _zhaoPianBtn.backgroundColor = [UIColor yellowColor];
    }
    return _zhaoPianBtn;
}

- (UIButton *)liulanBtn {
    if (!_liulanBtn) {
        _liulanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_liulanBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _liulanBtn.tag = 1103;
//        _liulanBtn.backgroundColor = [UIColor redColor];
    }
    return _liulanBtn;
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [_uploadView removeFromSuperview];
}

@end























